package com.ruku.mapper;

import com.bean.WmsTBill;
import com.bean.WmsTBillDetails;
import com.bean.WmsTCustomer;
import org.apache.ibatis.annotations.*;

import java.util.List;
import java.util.Map;

public interface Ruku2Mapper {
    @Select("select * from wms_t_bill_details where billID = #{value}")
    @Results(@Result(column = "billID",property = "wmsTBill",one = @One(select = "com.ruku.mapper.Ruku2Mapper.selbills")))
    public List<WmsTBillDetails> selectBill(String billID);

    @Select("select * from wms_t_bill where billID = #{value}")
    @Results(@Result(column = "customerID",property = "wmsTCustomer",one = @One(select = "com.ruku.mapper.Ruku2Mapper.selcust")))
    public WmsTBill selbills(String billID);

    @Select("select * from wms_t_customer where custID = #{value}")
    public WmsTCustomer selcust(String custID);

    @Select("<script>SELECT wms_t_bill_details.*,wms_t_customer.custName from wms_t_bill_details\n" +
            "        left join wms_t_bill on wms_t_bill_details.billID = wms_t_bill.billID\n" +
            "        LEFT JOIN wms_t_customer on wms_t_bill.customerID = wms_t_customer.custID\n" +
            "        WHERE billType='0' and billState='3' and billIsDel='0'\n" +
            "        <if test=\"custName != null and custName != ''\">\n" +
            "            and wms_t_bill_details.billID in (select wms_t_bill.billID from wms_t_bill where customerID in(SELECT custID FROM wms_t_customer WHERE wms_t_customer.custName = #{custName}))\n" +
            "        </if>\n" +
            "        <if test=\"start != null and start != ''\">\n" +
            "            <if test=\"end != null and end != ''\">\n" +
            "                and wms_t_bill_details.detailsEditTime BETWEEN #{start} AND #{end}\n" +
            "            </if>\n" +
            "        </if>\n" +
            "        <if test=\"billID != null and billID != ''\">\n" +
            "            and wms_t_bill.billID = #{billID};\n" +
            "        </if></script>")
    public List<Map<String, Object>> selectdetails(String start, String end, String custName, String billID);
}
